<template>
  <div>
    <Top
      :title="this.$route.params.text == 'onAdd' ? '添加地址' : '编辑地址'"
    ></Top>
    <van-address-edit
      v-if="this.$route.params.text == 'onAdd'"
      :area-list="areaList"
      
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      show-set-default
      @save="onSave"
    />
    <van-address-edit
      v-else
      :area-list="areaList"
      :address-info="AddressInfo"
      show-delete
      show-set-default
      @save="onupDate"
      @delete="onDelete"
    />
  </div>
</template>

<script>
import { address,updateAddress,deleteAddress } from "@/common/api/address";
import Top from "@/views/login/top";
import { areaList } from "@vant/area-data";
export default {
  components: {
    Top,
  },
  data() {
    return {
     AddressInfo:{},
      areaList,
      searchResult: [],
    };
  },
  methods: {
    onSave(content) {
      content.isDefault = content.isDefault == true ? 1 : 0;
      // 发起请求==》新增地址
      address(content).then((res) => {
        this.$router.push("/path");
      });
    },
    onupDate(e) {
      // // 发起请求==修改收货地址
      updateAddress(e).then(res=>{
        console.log(res);
      })
  

    },
    onDelete(e) {
      deleteAddress(e.id).then(res=>{
        console.log(res);
      })
    },
    
  },
  mounted(){
    this.AddressInfo=this.$route.params.info
   
    
  
  }
};
</script>

<style scoped>
::v-deep .van-button--danger {
  background-color: #b0352f;
  border: none;
}
</style>